#delimit;
*for REStat paper, "Breastfeeding and Children's Early Cognitive Outcomes."
log using d:/data/kind2.log, replace;
clear;
set mem 40m;
set more off;
set matsize 800;

use d:/data/kind2;

gen wkr0x = int(wkr0);
drop wkr0;

**summarize [fweight = wkr0x];

summarize [fweight = wkr0x];

summarize if bfeed==0 [fweight = wkr0x];
summarize if bfeed==1 [fweight = wkr0x];
summarize if bf1==1 [fweight = wkr0x];
summarize if bf23==1 [fweight = wkr0x];
summarize if bf45==1 [fweight = wkr0x];
summarize if bf6p==1 [fweight = wkr0x];


replace smoke = 0 if smokedv == 1;
replace csect = 0 if csectdv == 1;
replace r1ptest = 0 if r1ptestd == 1;
replace regne = 0 if regdv==1;
replace regs = 0 if regdv==1;
replace regw = 0 if regdv==1;
replace regnc = 0 if regdv==1;

replace gestlt35 = 0 if gestdv == 1;
replace gest3537 = 0 if gestdv == 1;
replace bwtvl = 0 if bwtdv == 1;
replace bwtlow = 0 if bwtdv == 1;
replace agebirth = 0 if agedv == 1;
replace pwork16 = 0 if pworkdv == 1;
replace pwork712 = 0 if pworkdv == 1;
*replace prework = 0 if pworkdv == 1;
replace backw0 = 0 if backwdv == 1;
replace backw13 = 0 if backwdv == 1;
replace backw46 = 0 if backwdv == 1;
replace backw6p = 0 if backwdv == 1;
replace wicp = 0 if wicpdv == 1;
replace bfathed = 0 if dadeddv == 1;
replace roft3 = 0 if roftdv == 1;
replace roft4 = 0 if roftdv == 1;

**not sure about this one, okay, not significant anyway;
replace dadocc = 0 if doccdv == 1;

**plain model;
reg kmathtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x], robust;

reg kreadtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x], robust;

**add maternal employment;
reg kmathtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv
backw13 backw46 backw6p backwdv [pweight = wkr0x], robust;

reg kreadtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv backw13 backw46 backw6p backwdv
[pweight = wkr0x], robust;

**add parenting score, hhinc;
reg kmathtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
r1ptest r1ptestd roft3 roft4 roftdv
backw13 backw46 backw6p backwdv khhinc [pweight = wkr0x], robust;

reg kreadtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv backw13 backw46 backw6p backwdv
r1ptest r1ptestd roft3 roft4 roftdv khhinc [pweight = wkr0x], robust;


**now with bf dummy variables;
**plain model;
reg kmathtx bf1 bf23 bf45 bf6p female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv [pweight = wkr0x], robust;

reg kreadtx bf1 bf23 bf45 bf6p female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv [pweight = wkr0x], robust;

**add maternal employment;
reg kmathtx bf1 bf23 bf45 bf6p female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv
backw13 backw46 backw6p backwdv [pweight = wkr0x], robust;

reg kreadtx bf1 bf23 bf45 bf6p female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv backw13 backw46 backw6p backwdv
[pweight = wkr0x], robust;

**add parenting score, hhinc;
reg kmathtx bf1 bf23 bf45 bf6p female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
r1ptest r1ptestd roft3 roft4 roftdv 
backw13 backw46 backw6p backwdv khhinc [pweight = wkr0x], robust;

reg kreadtx bf1 bf23 bf45 bf6p female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv backw13 backw46 backw6p backwdv
r1ptest r1ptestd khhinc roft3 roft4 roftdv [pweight = wkr0x], robust;

**next, supplementation;
replace bf1s = 0 if bf1 == 0;
replace bf23s = 0 if bf23 == 0;
replace bf45s01 = 0 if bf45 == 0;
replace bf45s23 = 0 if bf45 == 0;
replace bf6ps01 = 0 if bf6p == 0;
replace bf6ps23 = 0 if bf6p == 0;
replace bf6ps45 = 0 if bf6p == 0;

summarize bf1s bf23s bf45s01 bf45s23 bf45s01 bf45s23 bf6ps01 bf6ps23 bf6ps45;

**plain model;
reg kmathtx bf1 bf1s bf23 bf23s bf45 bf45s01 bf45s23 bf6p bf6ps01 bf6ps23 bf6ps45
female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv [pweight = wkr0x], robust;

reg kreadtx bf1 bf1s bf23 bf23s bf45 bf45s01 bf45s23 bf6p bf6ps01 bf6ps23 bf6ps45
female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv [pweight = wkr0x], robust;


**try iv regression with plain model;
**plain model;

regress bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv law bfrate [pweight = wkr0x], robust;

regress kmathtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv law bfrate [pweight = wkr0x], robust;

regress kreadtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv law bfrate [pweight = wkr0x], robust;


*does iv affect outcome?;

ivregress 2sls kmathtx female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv (bfeed = bfrate law) [pweight = wkr0x], robust;

ivregress 2sls kreadtx female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv (bfeed = bfrate law) [pweight = wkr0x], robust;

**now try stratifying as referee suggested;
reg kmathtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x] if black == 0 & hispanic ==0, robust;

reg kreadtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x] if black == 0 & hispanic ==0, robust;

reg kmathtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x] if black == 1, robust;

reg kreadtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x] if black == 1, robust;

reg kmathtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x] if hispanic == 1, robust;

reg kreadtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x] if hispanic == 1, robust;

**by education;
reg kmathtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x] if momed < 12, robust;

reg kreadtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x] if momed < 12, robust;

reg kmathtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x] if momed == 12, robust;

reg kreadtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x] if momed == 12, robust;

reg kmathtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x] if momed > 12, robust;

reg kreadtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x] if momed > 12, robust;

**by age at birth;
reg kmathtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x] if agedv == 0 & agebirth<=22, robust;

reg kreadtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x] if agedv == 0 & agebirth<=22, robust;

reg kmathtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x] if agedv == 0 & agebirth >22 & agebirth < 30, robust;

reg kreadtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x] if agedv == 0 & agebirth > 22 & agebirth < 30, robust;

reg kmathtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x] if agedv == 0 & agebirth>=30, robust;

reg kreadtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x] if agedv == 0 & agebirth>=30, robust;


**now try like brooks-gunn and british cohort data, bf for one month or more;

gen bf23p = bf23;
replace bf23p = 1 if bf45 == 1;
replace bf23p = 1 if bf6p == 1;

summarize bf23p;

reg kmathtx bf23p female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x], robust;

reg kreadtx bf23p female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
wicp wicpdv bfathed dadeddv [pweight = wkr0x], robust;

**what if interact bfeed with parenting score;

gen bfncats = bfeed*r1ptest;
gen bfncdv = bfeed*r1ptestd;

reg kmathtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv 
r1ptest r1ptestd roft3 roft4 roftdv 
backw13 backw46 backw6p backwdv khhinc bfncats bfncdv [pweight = wkr0x], robust;

reg kreadtx bfeed female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv backw13 backw46 backw6p backwdv
r1ptest r1ptestd khhinc roft3 roft4 roftdv bfncats bfncdv [pweight = wkr0x], robust;



**now twin sample;
keep if twin==1;

sort i_twinpr;
by i_twinpr:  generate x=_N;

keep if x==2;

summarize x;

by i_twinpr:  egen bfm = mean(bfeed);
by i_twinpr:  egen bfm1 = mean(bf1);
by i_twinpr:  egen bfm2 = mean(bf23);
by i_twinpr:  egen bfm3 = mean(bf45);
by i_twinpr:  egen bfm4 = mean(bf6p);


**drop if bfm == 0;
**drop if bfm == 1;
*drop if bfm1 == 1;
*drop if bfm2 == 1;
*drop if bfm3 == 1;
*drop if bfm4 == 1;
*drop if bfm1==0 & bfm2==0 & bfm3==0 & bfm4==0;

**reg kmathtx bf1 bf23 bf45 bf6p female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv [pweight = wkr0x], robust;

**reg kreadtx bf1 bf23 bf45 bf6p female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv [pweight = wkr0x], robust;

**areg kmathtx bf1 bf23 bf45 bf6p female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv [pweight = wkr0x], absorb(i_twinpr) robust;

**areg kreadtx bf1 bf23 bf45 bf6p female black hispanic asian chinese amerind twin border1 border2
bwtvl bwtlow marbirth agebirth momed prenat smoke regnc regs regw foreign csect gestlt35 gest3537 wicp wicpdv
bfathed dadeddv
pwork16 pwork712 smokedv csectdv regdv gestdv bwtdv agedv pworkdv [pweight = wkr0x], absorb(i_twinpr) robust;




log close;
